import requests,time

host = '192.168.1.232'
port = 8899
url = 'http://%s:%d/analyze' % (host, port)
# url = 'http://127.0.0.1:5000/predict'
def predict_result():
    # Initialize image path
    image_path = r'/home/ubuntu/data/Image_Retrieval/dataset/feature_test/0/5008.jpg'
    image = open(image_path, 'rb').read()
    payload = {'image': image}


    start = time.time()
    # Submit the request.
    r = requests.post(url, files=payload).json()
    # Ensure the request was successful.

    print(r,'\n',time.time()-start,'1111111')
    if r['success']:
        # Loop over the predictions and display them.
        for (i, result) in enumerate(r['predictions']):
            print('{}. {}: {:.4f}'.format(i + 1, result['label'],
                                          result['probability']))
    # Otherwise, the request failed.
    else:
        print('Request failed')

if  __name__ == '__main__':

    predict_result()